package com.woniu.dao;

import com.woniu.entity.User;
import com.woniu.entity.UserExample;
import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

public interface UserMapper {
    long countByExample(UserExample example);

    int deleteByExample(UserExample example);

    int deleteByPrimaryKey(Integer id);

    int insert(User record);

    int insertSelective(User record);

    List<User> selectByExample(UserExample example);

    User selectByPrimaryKey(Integer id);

    int updateByExampleSelective(@Param("record") User record, @Param("example") UserExample example);

    int updateByExample(@Param("record") User record, @Param("example") UserExample example);

    int updateByPrimaryKeySelective(User record);

    int updateByPrimaryKey(User record);

    @Select("select p.percode \n" +
            "from rbac_perms p inner join rbac_role_perm rp on (p.id=rp.permid)\n" +
            "\t\t\t\t\t\t\t\t\tinner join rbac_user_role ur on (ur.roleid = rp.roleid)\n" +
            "\t\t\t\t\t\t\t\t\tinner join rbac_user u on (u.id = ur.userid)\n" +
            "where u.username=#{username}")
    List<String> selectPercodeByRole(String username);

    @Select("select p.percode\n" +
            "from rbac_perms p inner join rbac_user_perm up on (p.id = up.permid)\n" +
            "\t\t\t\t\t\t\t\t\tinner join rbac_user u on (u.id = up.userid)\n" +
            "where u.username=#{username}")
    List<String> selectPercodeByPerm(String username);

    @Select("select p.id from rbac_perms p inner join rbac_user_perm up on(p.id=up.permid)\n" +
            "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t where up.userid=#{userid}")
    List<Integer> selectPermsidByUserid(Integer userid);

    @Delete("delete from rbac_user_perm where userid=#{userid}")
    void deletePermsByUserid(Integer userid);

    @Insert("insert into rbac_user_perm(userid,permid) values(#{userid},#{permid})" )
    void addUserPerms(@Param("userid") Integer userid,@Param("permid") Integer permid);
}